//
//  DriverChooseCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/21.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "DriverChooseCell.h"

@interface DriverChooseCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UITextField *driverField;

@end

@implementation DriverChooseCell

+ (instancetype)DriverChooseCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"DriverChooseCell";
    DriverChooseCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[DriverChooseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, ScreenW - 30, 60)];
        self.bgView.backgroundColor = HexColor(0xF7F7FA);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.height = self.bgView.nim_bottom;
        
        self.driverField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, self.bgView.nim_width, 60)];
        self.driverField.backgroundColor = HexColor(0xffffff);
        self.driverField.placeholder = @"请输入手机号搜索";
        self.driverField.font = [UIFont systemFontOfSize:16];
        self.driverField.keyboardType = UIKeyboardTypePhonePad;
        UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, self.driverField.nim_height)];
        UIButton *searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, (self.driverField.nim_height - 30) * 0.5, 40, 30)];
        [searchBtn setTitle:@"搜索" forState:0];
        [searchBtn setTitleColor:HexColor(0x2B2C44) forState:0];
        searchBtn.titleLabel.font = BoldFontOfSize(16);
        [searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
        [rightView addSubview:searchBtn];
        self.driverField.rightView = rightView;
        self.driverField.rightViewMode = UITextFieldViewModeAlways;
        UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, self.driverField.nim_height)];
        self.driverField.leftView = leftView;
        self.driverField.leftViewMode = UITextFieldViewModeAlways;
        
        [self.bgView addSubview:self.driverField];
    }
    return self;
}

- (void)searchClick {
    if (![FactoryMethod isNull:self.driverField.text]) {
        if ([FactoryMethod isPhone:self.driverField.text]) {
            if (self.searchBlock) {
                self.searchBlock(self.driverField.text);
            }
        }else {
            [MBProgressHUD leShowFailedHUD:MAIN_WINDOW message:@"请输入正确的手机号"];
        }
    }
}

-(void)setSearchText:(NSString *)searchText {
    _searchText = searchText;
    self.driverField.text = searchText.length ? searchText : @"";
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
